import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  // 状态
  state: () => ({
    count: 0,
    name: 'Vue 3 + Pinia'
  }),

  // 计算属性
  getters: {
    doubleCount: (state) => state.count * 2
  },

  // 方法（可以是同步或异步）
  actions: {
    increment() {
      this.count++
    },
    decrement() {
      this.count--
    },
    async asyncIncrement() {
      await new Promise((resolve) => setTimeout(resolve, 1000))
      this.count++
    }
  }
})
